/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package respaldos;

import dao.DaoUsuarios;
import java.sql.SQLException;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import modelos.Usuario;


/**
 *
 * @author Adrian
 */
public class BeanUsuarioActual {
     private  HttpServletRequest httpServletRequest;
    private  FacesContext faceContext;
    private FacesMessage facesMessage;
    
    private String cedula;
    private Usuario userActual;

    public String getCedula() {
        return cedula;
    }

    public void setCedula(String cedula) {
        this.cedula = cedula;
    }

    public Usuario getUserActual() {
        return userActual;
    }

    public void setUserActual(Usuario userActual) {
        this.userActual = userActual;
    }
    
   /**
     * Creates a new instance of BeanUsuarioActual
     */
    public BeanUsuarioActual() {
        
    }
     public String BuscarUsuario() throws SQLException
             
    {
        Usuario user=DaoUsuarios.getInstance().BuscarUsuario(cedula);
        if(user!=null)
        {
             faceContext=FacesContext.getCurrentInstance();
        httpServletRequest=(HttpServletRequest)faceContext.getExternalContext().getRequest();
            httpServletRequest.getSession().setAttribute("sessionUsuario", user.getCedula());
            facesMessage=new FacesMessage(FacesMessage.SEVERITY_INFO, "Acceso Correcto", null);
            faceContext.addMessage(null, facesMessage);
          userActual=user;
          return "yesUsuario" ; 
        }
        
        else
        {
            return "noUsuario";
        }
        
    }
    
    
    
    
}
